package com.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Description: HJ67 24点游戏算法
 *
 * 注意：由于有除，有 74/3=24 73/3=24 72/3=24
 * 所以sum要用浮点型
 * @author weiruibai.vendor
 * Date: 2022/8/23 10:14
 */
public class HJ67 {

    public static void main(String[] args) throws IOException {
        System.out.println(74/3);
        System.out.println(73/3);
        System.out.println(72/3);
        test1();
    }

    private static void test1() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = bufferedReader.readLine()) != null) {
            String[] strs = str.split(" ");
            boolean[] visited = new boolean[4];
            System.out.println(process(strs, 0, 0f, visited));
            ;
        }
    }

    /**
     * 2 2 7 6
     * 7 9 10 9
     * 注意：由于有除，有 74/3=24 73/3=24 72/3=24
     * 所以sum要用浮点型！！！！！！！！
     * @param strs
     * @param i
     * @param sum
     * @return
     */
    private static boolean process(String[] strs, int i, float sum, boolean[] visited) {
        if (i == 4 && sum == 24) {
            return true;
        }
        for (int j = 0; j < 4; j++) {
            if (!visited[j]) {
                visited[j] = true;
                // +
                boolean b = process(strs, i + 1, sum + Float.parseFloat(strs[j]), visited);
                if (b) {
                    return true;
                }
                // -
                b = process(strs, i + 1, sum - Float.parseFloat(strs[j]), visited);
                if (b) {
                    return true;
                }
                // *
                b = process(strs, i + 1, sum * Float.parseFloat(strs[j]), visited);
                if (b) {
                    return true;
                }
                //
                b = process(strs, i + 1, sum / Float.parseFloat(strs[j]), visited);
                if (b) {
                    return true;
                }
                visited[j] = false;
            }
        }
        return false;
    }
}
